var util = require('../../../utils/utils.js');
const db = wx.cloud.database()
const addData = db.collection('FindTeam')
const app=getApp()
const _ = db.command


Page({

  /**
   * 页面的初始数据
   */
  data: {
    animLetterPop: {},
    FindTeam:{
      Topic:'',
      AcitivityName:"",
      type:'',
      Detail:"",
      wxNum:"",
      Time:"",
      avatar:"",
      index:1
    },

    Num: '0',
    index:"4",
    array: ['体育活动', '艺术活动', '学术活动', '其他活动'],
    objectArray: [
      {
        id: 0,
        name: '体育活动'
      },
      {
        id: 1,
        name: '艺术活动'
      },
      {
        id: 2,
        name: '学术活动'
      },
      {
        id: 3,
        name: '其他活动'
      },
      
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.app = getApp()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },


  onShow: function () {
    this.pop2();
    this.app.show(this, 'animShow',1);

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },


  pop2: function(){

    var animationLetterPop = wx.createAnimation({
      duration:3000,
      timingFunction:'ease',
      delay: 0
    });

    animationLetterPop.translateY(-600).step();

    this.setData({
      animLetterPop: animationLetterPop.export(),
    })
  },
  AddTopic:function(e)
  {
      this.setData({
        ['FindTeam.Topic']:e.detail.value
      })
  },

  AddAcitivityName:function(e)
  {
      this.setData({
        ['FindTeam.AcitivityName']:e.detail.value
      })
  },

  Adddetail:function(e)
  {
      this.setData({
        ['FindTeam.Detail'] :e.detail.value
      })
  },
  Addwx:function(e)
  {
    this.setData({
      ['FindTeam.wxNum']:e.detail.value
    })
  },
  submit:function()
  {
      this.getTime();
      this.data.FindTeam.avatar=app.globalData.avatarUrl
      addData.add({
        data:{
          FindTeam:this.data.FindTeam
        },
        success: function(res) {
          // res 是一个对象，其中有 _id 字段标记刚创建的记录的 id
          console.log(res);
          db.collection('user').where({
            _openid:app.globalData.openid
          }).update({
            // data 传入需要局部更新的数据
            data: {
              // 表示将 done 字段置为 true
              ['publish.FindTeam']:_.push([res._id])
            },
          
          })
          wx.navigateTo({ 
            url: '/pages/manager/success/success', 
          }) 
        }
      })
    },
    bindPickerChange: function (e) {
      console.log('picker发送选择改变，携带值为', e.detail.value)
      this.setData({
        index: e.detail.value
      })
      this.data.FindTeam.type=this.data.array[this.data.index]
    },
    getTime:function(){
      console.log("yes")
       var time = util.formatTime(new Date());
       this.data.FindTeam.Time=time;
  
    },
    handleBack: function(){
      wx.switchTab({
        url: '/pages/index/index',
      })
    },



  
})